<script setup>

import SimpleAuthConfig from "./SimpleAuthConfig.vue";
import {reactive} from "vue";
import {ConfigManager} from "../ConfigManager.ts";
import {AuthYYJSWIFI} from "../../wailsjs/go/main/App";
import {useMessage} from "naive-ui";

const message = useMessage()
const state = reactive({
  username: "",
  passwd: "",
})


function onSave() {
  console.log("onSave...")
  ConfigManager.appConfig.yyjswifi.username = state.username;
  ConfigManager.appConfig.yyjswifi.password = state.passwd;
  ConfigManager.Update();
}

function onLogin(username, password) {
  AuthYYJSWIFI(username, password).then((v) => {
    message.success(v)
  }, (err) => {
    message.error(err)
  })
}

ConfigManager.GetConfig().then((v) => {
  state.username = v.yyjswifi.username;
  state.passwd = v.yyjswifi.password;
})

</script>

<template>
  <n-flex vertical>
    <n-alert type="info" closable>
      账号: yy + 199手机号 <br>密码: 123456
    </n-alert>
    <SimpleAuthConfig v-model:username="state.username" v-model:passwd="state.passwd" @test="onLogin" @save="onSave">
    </SimpleAuthConfig>
  </n-flex>
</template>

<style scoped>

</style>